From 847718da4591488afbd3c2f7270cc3b28df4576d Mon Sep 17 00:00:00 2001 From: robertlipe Date: Mon, 7 Apr 2014 02:54:07 +0000 Subject: [PATCH] A bunch of mechanical NEW_STRING cleanups, pencil whipping code against replacements.. --- gpsbabel/bcr.cc | 1 - gpsbabel/csv_util.cc | 55 ++-------------------- gpsbabel/exif.cc | 22 ++++----- gpsbabel/g7towin.cc | 2 +- gpsbabel/garmin.cc | 3 -- gpsbabel/garmin_tables.cc | 6 +-- gpsbabel/ggv_ovl.cc | 4 +- gpsbabel/gpx.cc | 18 +------- gpsbabel/gtrnctr.cc | 97 +-------------------------------------- gpsbabel/humminbird.cc | 6 +-- gpsbabel/kml.cc | 12 ++--- gpsbabel/magproto.cc | 37 ++------------- gpsbabel/mapsend.cc | 38 ++------------- gpsbabel/mtk_logger.cc | 4 +- gpsbabel/osm.cc | 20 +++----- gpsbabel/pcx.cc | 4 +- gpsbabel/psitrex.cc | 13 ------ gpsbabel/skytraq.cc | 6 +-- gpsbabel/stmsdf.cc | 7 ++- gpsbabel/tiger.cc | 3 +- gpsbabel/util.cc | 3 +- 21 files changed, 51 insertions(+), 310 deletions(-) diff --git a/gpsbabel/bcr.cc b/gpsbabel/bcr.cc index d2de9dada..d1e234717 100644 --- a/gpsbabel/bcr.cc +++ b/gpsbabel/bcr.cc @@ -492,7 +492,6 @@ bcr_route_header(const route_head* route) bcr_write_line(fout, "[ROUTE]", NULL, NULL); /* route section */ -// xasprintf(&sout, "%d,%d,%d,%d", emin, nmax, emax, nmin); sout = QString::number(emin) + "," + QString::number(nmax) + "," + QString::number(emax) + "," + diff --git a/gpsbabel/csv_util.cc b/gpsbabel/csv_util.cc index 4554ca0b6..df44a5cc9 100644 --- a/gpsbabel/csv_util.cc +++ b/gpsbabel/csv_util.cc @@ -175,45 +175,6 @@ static UrlLink* link_; /* usage: p = csv_stringclean(stringtoclean, "&,\"") */ /* (strip out ampersands, commas, and quotes. */ /*********************************************************************/ -#if 0 -char* -#ifdef DEBUG_MEM -CSV_STRINGCLEAN(const char* string, const char* chararray, DEBUG_PARAMS) -#else -csv_stringclean(const char* string, const char* chararray) -#endif -{ - char* p1; - char* p2; - const char* cp; - char* tmp = xxstrdup(string,file,line); - - if ((! string) || (! chararray)) { - return (tmp); - } - - /* p2 - end of the original string */ - p2 = tmp + strlen(tmp); - - cp = chararray; - - while (*cp) { - p1 = tmp; - while (*p1) { - if (*cp == *p1) { - /* we don't want this character! */ - memmove(p1, p1 + 1, (p2 - p1)); - p1[p2 - p1] = '\0'; - p2--; - } else { - p1++; - } - } - cp++; - } - return (tmp); -} -#else // Implement the C version via Qt - the reverse of most of our shims. char* csv_stringclean(const char* source, const char* chararray) @@ -222,7 +183,6 @@ csv_stringclean(const char* source, const char* chararray) QString cleansed(csv_stringclean(QString(source), chararray)); return xstrdup(cleansed); } -#endif QString csv_stringclean(const QString& source, const QString& to_nuke) @@ -232,17 +192,12 @@ csv_stringclean(const QString& source, const QString& to_nuke) return r.remove(QRegExp(regex)); } -/***********************************************************************************/ -/* csv_stringtrim() - trim whitespace and leading and trailing enclosures (quotes) */ -/* returns a copy of the modified string */ -/* usage: p = csv_stringtrim(string, "\"", 0) */ -/***********************************************************************************/ +// csv_stringtrim() - trim whitespace and leading and trailing +// enclosures (quotes) +// returns a copy of the modified string +// usage: p = csv_stringtrim(string, "\"", 0) char* -#ifdef DEBUG_MEM -CSV_STRINGTRIM(const char* string, const char* enclosure, int strip_max, DEBUG_PARAMS) -#else csv_stringtrim(const char* string, const char* enclosure, int strip_max) -#endif { static const char* p1 = NULL; char* p2 = NULL; @@ -1724,7 +1679,7 @@ xcsv_waypt_pr(const Waypoint* wpt) UrlLink l = wpt->GetUrlLink(); buff += QString().sprintf(fmp->printfc, CSTR(l.url_)); } else { - buff += QString().sprintf(fmp->val && *fmp->val ? fmp->val : "\"\""); + buff += QString().sprintf(fmp->printfc, fmp->val && *fmp->val ? fmp->val : "\"\""); } } break; diff --git a/gpsbabel/exif.cc b/gpsbabel/exif.cc index fbb473131..6181d2669 100644 --- a/gpsbabel/exif.cc +++ b/gpsbabel/exif.cc @@ -212,19 +212,19 @@ exif_type_size(const uint16_t type) return size; } -static char* +// TODO: If this were actually ever used (!?!?!) it could probably be +// replaced by return QDateTime(time).toString("yyyy/MM/dd, hh:mm:ss); +static QString exif_time_str(const time_t time) { struct tm tm; - char* res; tm = *localtime(&time); tm.tm_year += 1900; tm.tm_mon += 1; - xasprintf(&res, "%04d/%02d/%02d, %02d:%02d:%02d", - tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); - return res; + return QString().sprintf("%04d/%02d/%02d, %02d:%02d:%02d", + tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); } static char* @@ -1396,7 +1396,7 @@ exif_wr_init(const char* fname) if (exif_time_ref == 0) { fatal(MYNAME ": No valid timestamp found in picture!\n"); } - +abort(); xasprintf(&tmpname, "%s.jpg", fname); fout = gbfopen_be(tmpname, "wb", MYNAME); xfree(tmpname); @@ -1443,7 +1443,7 @@ exif_write(void) warning(MYNAME ": No matching point with name \"%s\" found.\n", opt_name); } } else { - char* str = exif_time_str(exif_time_ref); + QString str = exif_time_str(exif_time_ref); track_disp_all(NULL, NULL, exif_find_wpt_by_time); route_disp_all(NULL, NULL, exif_find_wpt_by_time); @@ -1454,16 +1454,14 @@ exif_write(void) if (exif_wpt_ref == NULL) { warning(MYNAME ": No point with a valid timestamp found.\n"); } else if (abs(exif_time_ref - exif_wpt_ref->creation_time.toTime_t()) > frame) { - warning(MYNAME ": No matching point found for image date %s!\n", str); + warning(MYNAME ": No matching point found for image date %s!\n", CSTR(str)); if (exif_wpt_ref != NULL) { - char* str = exif_time_str(exif_wpt_ref->creation_time.toTime_t()); + QString str = exif_time_str(exif_wpt_ref->creation_time.toTime_t()); warning(MYNAME ": Best is from %s, %d second(s) away.\n", - str, abs(exif_time_ref - exif_wpt_ref->creation_time.toTime_t())); - xfree(str); + CSTR(str), abs(exif_time_ref - exif_wpt_ref->creation_time.toTime_t())); } exif_wpt_ref = NULL; } - xfree(str); } if (exif_wpt_ref != NULL) { diff --git a/gpsbabel/g7towin.cc b/gpsbabel/g7towin.cc index 3c1ee51a0..e2f13e263 100644 --- a/gpsbabel/g7towin.cc +++ b/gpsbabel/g7towin.cc @@ -462,7 +462,7 @@ data_read(void) wpt = new Waypoint; cdata += parse_coordinates(cdata, datum, grid, &wpt->latitude, &wpt->longitude, MYNAME); - xasprintf(&wpt->shortname, "Event%d", ++event_ct); + wpt->shortname = QString("Event%1").arg(++event_ct); while (isspace(*cdata)) { cdata++; } diff --git a/gpsbabel/garmin.cc b/gpsbabel/garmin.cc index b264e69f9..a77a0233e 100644 --- a/gpsbabel/garmin.cc +++ b/gpsbabel/garmin.cc @@ -945,9 +945,6 @@ waypoint_prepare(void) } else { if (global_opts.smart_names && wpt->gc_data->diff && wpt->gc_data->terr) { -#if 0 - xasprintf(&src, "%s %s", &wpt->shortname[2], src); -#endif snprintf(obuf, sizeof(obuf), "%s%d/%d %s", get_gc_info(wpt), wpt->gc_data->diff, wpt->gc_data->terr, diff --git a/gpsbabel/garmin_tables.cc b/gpsbabel/garmin_tables.cc index ed041438e..3bd09f0e9 100644 --- a/gpsbabel/garmin_tables.cc +++ b/gpsbabel/garmin_tables.cc @@ -1025,10 +1025,8 @@ gt_lookup_datum_index(const char* datum_str, const char* module) result = GPS_Lookup_Datum_Index(name); if (result < 0) { - char* tmp; - xasprintf(&tmp, "%s mean", datum_str); - result = GPS_Lookup_Datum_Index(tmp); - xfree(tmp); + QString tmp = QString(datum_str) + " mean"; + result = GPS_Lookup_Datum_Index(CSTR(tmp)); } is_fatal(result < 0, diff --git a/gpsbabel/ggv_ovl.cc b/gpsbabel/ggv_ovl.cc index 80318bf52..2de58a82c 100644 --- a/gpsbabel/ggv_ovl.cc +++ b/gpsbabel/ggv_ovl.cc @@ -137,11 +137,11 @@ ggv_ovl_read(void) if (group > 1) { route_add_head(rte); route_ct++; - xasprintf(&rte->rte_name, "Route %d", route_ct); + trk->rte_name = QString("Route %1").arg(route_ct); } else { track_add_head(trk); track_ct++; - xasprintf(&trk->rte_name, "Track %d", track_ct); + trk->rte_name = QString("Track %1").arg(track_ct); } for (j = 0; j < points; j++) { diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index 20dc6c772..f066cf2c3 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -1524,11 +1524,7 @@ gpx_write_common_description(const Waypoint* waypointp, QString oname) writer->writeOptionalTextElement("name", oname); writer->writeOptionalTextElement("cmt", waypointp->description); -#if NEW_STRINGS if (!waypointp->notes.isEmpty()) { -#else - if (waypointp->notes && waypointp->notes[0]) { -#endif writer->writeTextElement("desc", waypointp->notes); } else { writer->writeOptionalTextElement("desc", waypointp->description); @@ -1582,13 +1578,9 @@ gpx_track_hdr(const route_head* rte) current_trk_head = rte; writer->writeStartElement("trk"); -#if NEW_STRINGS writer->writeOptionalTextElement("name", rte->rte_name); writer->writeOptionalTextElement("desc", rte->rte_desc); -#else - writer->writeOptionalTextElement("name", QString::fromUtf8(rte->rte_name)); - writer->writeOptionalTextElement("desc", QString::fromUtf8(rte->rte_desc)); -#endif + if (rte->rte_num) { writer->writeTextElement("number", QString::number(rte->rte_num)); } @@ -1626,11 +1618,7 @@ gpx_track_disp(const Waypoint* waypointp) /* GPX doesn't require a name on output, so if we made one up * on input, we might as well say nothing. */ -#if NEW_STRINGS QString oname; -#else - const char* oname; -#endif oname = global_opts.synthesize_shortnames ? mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname; @@ -1693,11 +1681,7 @@ gpx_route_hdr(const route_head* rte) static void gpx_route_disp(const Waypoint* waypointp) { -#if NEW_STRINGS QString oname; -#else - const char* oname; -#endif fs_xml* fs_gpx; writer->writeStartElement("rtept"); writer->writeAttribute("lat", toString(waypointp->latitude)); diff --git a/gpsbabel/gtrnctr.cc b/gpsbabel/gtrnctr.cc index 2c13d0794..5184409fe 100644 --- a/gpsbabel/gtrnctr.cc +++ b/gpsbabel/gtrnctr.cc @@ -416,16 +416,10 @@ gtc_crs_hdr(const route_head* rte) gtc_lap_start(NULL); gtc_new_study_lap(rte); route_disp(rte, gtc_study_lap); -#if NEW_STRINGS + if (!rte->rte_name.isEmpty()) { QString name = rte->rte_name.left(GTC_MAX_NAME_LEN); gtc_write_xml(0, QString("%1\n").arg(name)); -#else - if (rte->rte_name) { - char* name = xstrndup(rte->rte_name, GTC_MAX_NAME_LEN); - gtc_write_xml(0, "%s\n", name); - xfree(name); -#endif } else { gtc_write_xml(0, "New Course\n"); } @@ -528,38 +522,21 @@ gtc_trk_utc(xg_string args, const QXmlStreamAttributes*) void gtc_trk_lat(xg_string args, const QXmlStreamAttributes*) { -#if NEW_STRINGS wpt_tmp->latitude = args.toDouble(); -#else - wpt_tmp->latitude = atof(args); -#endif } void gtc_trk_long(xg_string args, const QXmlStreamAttributes*) { -#if NEW_STRINGS wpt_tmp->longitude = args.toDouble(); -#else - wpt_tmp->longitude = atof(args); -#endif } -#if NEW_STRINGS void gtc_trk_alt(xg_string args, const QXmlStreamAttributes*) { wpt_tmp->altitude = args.toDouble(); } -#else -void -gtc_trk_alt(xg_string args, const QXmlStreamAttributes*) -{ - wpt_tmp->altitude = atof(args); -} -#endif -#if NEW_STRINGS void gtc_trk_dist(const QString& args, const QXmlStreamAttributes*) { wpt_tmp->odometer_distance = args.toDouble(); @@ -572,59 +549,21 @@ void gtc_trk_cad(const QString& args, const QXmlStreamAttributes*) { wpt_tmp->cadence = args.toDouble(); } -#else -void -gtc_trk_dist(xg_string args, const QXmlStreamAttributes*) -{ - wpt_tmp->odometer_distance = atof(args); -} - -void -gtc_trk_hr(xg_string args, const QXmlStreamAttributes*) -{ - wpt_tmp->heartrate = atoi(args); -} -void -gtc_trk_cad(xg_string args, const QXmlStreamAttributes*) -{ - wpt_tmp->cadence = atoi(args); -} -#endif - -#if NEW_STRINGS void gtc_trk_pwr(xg_string args, const QXmlStreamAttributes*) { wpt_tmp->power = args.toDouble(); } -#else -void -gtc_trk_pwr(xg_string args, const QXmlStreamAttributes*) -{ - wpt_tmp->power = atof(args); -} -#endif void -#if NEW_STRINGS gtc_trk_spd(xg_string args, const QXmlStreamAttributes*) { WAYPT_SET(wpt_tmp, speed, args.toDouble()); } -#else -gtc_trk_spd(xg_string args, const QXmlStreamAttributes*) -{ - WAYPT_SET(wpt_tmp, speed, atof(args)); -} -#endif void -#if NEW_STRINGS gtc_wpt_crs_s(const QString& args, const QXmlStreamAttributes*) -#else -gtc_wpt_crs_s(const char*, const QXmlStreamAttributes* unusedattrs) -#endif { wpt_tmp = new Waypoint; } @@ -663,7 +602,6 @@ gtc_wpt_pnt_e(xg_string args, const QXmlStreamAttributes*) wpt_tmp = NULL; } -#if NEW_STRINGS void gtc_wpt_ident(const QString& args, const QXmlStreamAttributes*) { wpt_tmp->shortname = (args); @@ -686,39 +624,6 @@ void gtc_wpt_notes(const QString& args, const QXmlStreamAttributes*) { wpt_tmp->description = args; } -#else -void -gtc_wpt_ident(xg_string args, const QXmlStreamAttributes*) -{ - wpt_tmp->shortname = args; - /* Set also as notes for compatibility with garmin usb format */ - wpt_tmp->notes = args; -} - -void -gtc_wpt_lat(xg_string args, const QXmlStreamAttributes*) -{ - wpt_tmp->latitude = atof(args); -} - -void -gtc_wpt_long(xg_string args, const QXmlStreamAttributes*) -{ - wpt_tmp->longitude = atof(args); -} - -void -gtc_wpt_icon(xg_string args, const QXmlStreamAttributes*) -{ - wpt_tmp->icon_descr = args; -} - -void -gtc_wpt_notes(xg_string args, const QXmlStreamAttributes*) -{ - wpt_tmp->description = args; -} -#endif ff_vecs_t gtc_vecs = { ff_type_file, diff --git a/gpsbabel/humminbird.cc b/gpsbabel/humminbird.cc index 829fba0f9..a30157bdf 100644 --- a/gpsbabel/humminbird.cc +++ b/gpsbabel/humminbird.cc @@ -735,10 +735,9 @@ humminbird_write_waypoint(const Waypoint* wpt) be_write32(&hum.north, si_round(north)); QString name; -// NEW_STRING - remove extra ctor below. name = (global_opts.synthesize_shortnames) ? mkshort_from_wpt(wptname_sh, wpt) - : mkshort(wptname_sh, QString(wpt->shortname)); + : mkshort(wptname_sh, wpt->shortname); memset(&hum.name, 0, sizeof(hum.name)); memcpy(&hum.name, CSTR(name), name.length()); @@ -765,8 +764,7 @@ humminbird_track_head(const route_head* trk) trk_head = (humminbird_trk_header_t*) xcalloc(1, sizeof(humminbird_trk_header_t)); trk_points = (humminbird_trk_point_t*) xcalloc(max_points, sizeof(humminbird_trk_point_t)); -// NEW_STRING: remove speare ctor below. - name = mkshort(trkname_sh, QString(trk->rte_name)); + name = mkshort(trkname_sh, trk->rte_name); strncpy(trk_head->name, CSTR(name), sizeof(trk_head->name)-1); be_write16(&trk_head->trk_num, trk->rte_num); } diff --git a/gpsbabel/kml.cc b/gpsbabel/kml.cc index 19a98a92c..6430237bb 100644 --- a/gpsbabel/kml.cc +++ b/gpsbabel/kml.cc @@ -1176,12 +1176,10 @@ void kml_gc_make_balloonstyle(void) } static -char* +QString kml_lookup_gc_icon(const Waypoint* waypointp) { const char* icon; - char* rb; - /* This could be done so much better in C99 with designated * initializers... */ @@ -1230,8 +1228,7 @@ kml_lookup_gc_icon(const Waypoint* waypointp) break; } - xasprintf(&rb, "http://www.geocaching.com/images/kml/%s", icon); - return rb; + return QString("http://www.geocaching.com/images/kml/%1").arg(icon); } static const @@ -1394,7 +1391,6 @@ static void kml_write_cdata_element(const QString& name, const QString& value) static void kml_geocache_pr(const Waypoint* waypointp) { - char* is; const char* issues = ""; writer->writeStartElement("Placemark"); @@ -1416,10 +1412,10 @@ static void kml_geocache_pr(const Waypoint* waypointp) } writer->writeTextElement("styleUrl", "#geocache"); - is = kml_lookup_gc_icon(waypointp); writer->writeStartElement("Style"); writer->writeStartElement("IconStyle"); writer->writeStartElement("Icon"); + QString is = kml_lookup_gc_icon(waypointp); writer->writeTextElement("href", is); writer->writeEndElement(); // Close Icon tag writer->writeEndElement(); // Close IconStyle tag @@ -1474,8 +1470,6 @@ static void kml_geocache_pr(const Waypoint* waypointp) writer->writeEndElement(); // Close Point tag writer->writeEndElement(); // Close Placemark tag - - xfree(is); } /* diff --git a/gpsbabel/magproto.cc b/gpsbabel/magproto.cc index 33a8b1f78..55310654d 100644 --- a/gpsbabel/magproto.cc +++ b/gpsbabel/magproto.cc @@ -1382,17 +1382,11 @@ mag_waypt_pr(const Waypoint* waypointp) if (get_cache_icon(waypointp)) { icon_token = mag_find_token_from_descr(get_cache_icon(waypointp)); } -#if NEW_STRINGS + QString isrc = waypointp->notes.isEmpty() ? waypointp->description : waypointp->notes; QString owpt = global_opts.synthesize_shortnames ? mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname; QString odesc = isrc; -#else - String isrc = waypointp->notes ? waypointp->notes : waypointp->description; - char* owpt = global_opts.synthesize_shortnames ? - mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname; - char* odesc = isrc ? isrc : (char*)""; -#endif owpt = mag_cleanse(CSTRc(owpt)); if (global_opts.smart_icons && @@ -1409,11 +1403,7 @@ mag_waypt_pr(const Waypoint* waypointp) * to deliver turn-by-turn popups for street routing) allow a * cap on the comments delivered so we leave space for it to route. */ -#if NEW_STRINGS if (!odesc.isEmpty() && (wptcmtcnt++ >= wptcmtcnt_max)) { -#else - if (odesc && /* !is_file && */ (wptcmtcnt++ >= wptcmtcnt_max)) { -#endif odesc[0] = 0; } @@ -1427,11 +1417,6 @@ mag_waypt_pr(const Waypoint* waypointp) CSTRc(odesc), icon_token.toUtf8().data()); mag_writemsg(obuf); -#if NEW_STRINGS -#else - xfree(owpt); - xfree(odesc); -#endif if (!is_file) { if (mag_error) { @@ -1553,20 +1538,8 @@ mag_route_trl(const route_head* rte) } else { pbuff = buff2; } -#if NEW_STRINGS -// TODO: figure out what this code is trying to do. - sprintf(pbuff, "%s,%s", CSTR(waypointp->shortname), icon_token.toUtf8().data()); -#else - owpt = waypointp->shortname; - if (strlen(owpt) > sizeof(buff1) - 3) { - owpt[sizeof(buff1) - 3] = 0; - } - owpt = mag_cleanse(owpt); - - sprintf(pbuff, "%s,%s", owpt, icon_token.toUtf8().data()); - - xfree(owpt); -#endif + // Write name, icon tuple into alternating buff1/buff2 buffer. + sprintf(pbuff, "%s,%s", CSTR(waypointp->shortname), CSTR(icon_token)); if ((tmp == &rte->waypoint_list) || ((i % 2) == 0)) { char expbuf[1024]; @@ -1574,11 +1547,7 @@ mag_route_trl(const route_head* rte) expbuf[0] = 0; if (explorist) { snprintf(expbuf, sizeof(expbuf), "%s,", -#if NEW_STRINGS CSTRc(rte->rte_name)); -#else - rte->rte_name ? CSTRc(rte->rte_name) : ""); -#endif } sprintf(obuff, "PMGNRTE,%d,%d,c,%d,%s%s,%s", diff --git a/gpsbabel/mapsend.cc b/gpsbabel/mapsend.cc index a13d735bf..6f114cadf 100644 --- a/gpsbabel/mapsend.cc +++ b/gpsbabel/mapsend.cc @@ -298,27 +298,14 @@ mapsend_waypt_pr(const Waypoint* waypointp) QString tmp1 = mkshort(wpt_handle, sn); gbfputpstr(tmp1, mapsend_file_out); -#if NEW_STRINGS + // This is funny looking to ensure that no more than 30 bytes + // get written to the file. c = waypointp->description.length(); if (c > 30) { c = 30; } gbfputc(c, mapsend_file_out); gbfwrite(CSTR(waypointp->description), 1, c, mapsend_file_out); -#else - char* tmp = waypointp->description; - if (tmp) { - c = strlen(tmp); - } else { - c = 0; - } - - if (c > 30) { - c = 30; - } - gbfputc(c, mapsend_file_out); - gbfwrite(tmp, 1, c, mapsend_file_out); -#endif /* #, icon, status */ gbfputint32(++cnt, mapsend_file_out); @@ -393,13 +380,7 @@ mapsend_route_disp(const Waypoint* waypointp) route_wp_count++; /* waypoint name */ -#if NEW_STRINGS - c = waypointp->shortname.length(); -#else - c = waypointp->shortname ? strlen(waypointp->shortname) : 0; -#endif - gbfwrite(&c, 1, 1, mapsend_file_out); - gbfwrite(CSTRc(waypointp->shortname), 1, c, mapsend_file_out); + gbfputpstr(waypointp->shortname, mapsend_file_out); /* waypoint number */ gbfputint32(route_wp_count, mapsend_file_out); @@ -457,21 +438,8 @@ void mapsend_track_hdr(const route_head* trk) hdr.ms_version[1] = verstring[1]; gbfwrite(&hdr, sizeof(hdr), 1, mapsend_file_out); -#if NEW_STRINGS QString tname = trk->rte_name.isEmpty() ? "Track" : trk->rte_name; gbfputpstr(tname, mapsend_file_out); -#else - /* track name */ - char* tname; - if (!trk->rte_name) { - tname = xstrdup("Track"); - } else { - tname = xstrdup(trk->rte_name); - } - gbfputpstr(tname, mapsend_file_out); - - xfree(tname); -#endif /* total nodes (waypoints) this track */ i = 0; diff --git a/gpsbabel/mtk_logger.cc b/gpsbabel/mtk_logger.cc index 573ab8b0b..1fdf6c02a 100644 --- a/gpsbabel/mtk_logger.cc +++ b/gpsbabel/mtk_logger.cc @@ -752,13 +752,13 @@ static int add_trackpoint(int idx, unsigned long bmask, struct data_item* itm) if (global_opts.masked_objective& TRKDATAMASK && (trk_head == NULL || (mtk_info.track_event & MTK_EVT_START))) { char spds[50]; trk_head = route_head_alloc(); - xasprintf(&trk_head->rte_name, "track-%d", 1+track_count()); + trk_head->rte_name = QString("track-%1").arg(1 + track_count()); spds[0] = '\0'; if (mtk_info.speed > 0) { sprintf(spds, " when moving above %.0f km/h", mtk_info.speed/10.); } - xasprintf(&trk_head->rte_desc, "Log every %.0f sec, %.0f m%s" + trk_head->rte_desc = QString().sprintf("Log every %.0f sec, %.0f m%s" , mtk_info.period/10., mtk_info.distance/10., spds); track_add_head(trk_head); } diff --git a/gpsbabel/osm.cc b/gpsbabel/osm.cc index 66c3faff5..c23b937c0 100644 --- a/gpsbabel/osm.cc +++ b/gpsbabel/osm.cc @@ -433,10 +433,9 @@ osm_feature_ikey(const char* key) } -static char* +static QString osm_feature_symbol(const int ikey, const char* value) { - char* result; char buff[128]; QString key; @@ -444,12 +443,13 @@ osm_feature_symbol(const int ikey, const char* value) strncpy(&buff[1], value, sizeof(buff) - 1); key = QString::fromUtf8(buff); + + QString result; if (values.contains(key)) { - result = xstrdup(values.value(key)->icon); + result = values.value(key)->icon; } else { - xasprintf(&result, "%s:%s", osm_features[ikey], value); + result = QString("%1:%2").arg(osm_features[ikey]).arg(value); } - return result; } @@ -538,11 +538,7 @@ osm_node_tag(xg_string args, const QXmlStreamAttributes* attrv) } else if (strcmp(key, "name:en") == 0) { wpt->shortname = str; } else if ((ikey = osm_feature_ikey(key)) >= 0) { - char* id = osm_feature_symbol(ikey, value); - wpt->icon_descr = id; - if (id) { - xfree(id); - } + wpt->icon_descr = osm_feature_symbol(ikey, value); } else if (strcmp(key, "note") == 0) { if (wpt->notes.isEmpty()) { wpt->notes = str; @@ -827,11 +823,7 @@ osm_waypt_disp(const Waypoint* wpt) } osm_write_tag("name", wpt->shortname); -#if NEW_STRINGS osm_write_tag("note", (wpt->notes.isEmpty()) ? wpt->description : wpt->notes); -#else - osm_write_tag("note", (wpt->notes) ? wpt->notes : wpt->description); -#endif if (!wpt->icon_descr.isNull()) { osm_disp_feature(wpt); } diff --git a/gpsbabel/pcx.cc b/gpsbabel/pcx.cc index a2cdb7cd1..e68e210ce 100644 --- a/gpsbabel/pcx.cc +++ b/gpsbabel/pcx.cc @@ -364,8 +364,8 @@ pcx_track_hdr(const route_head* trk) route_ctr++; snprintf(buff, sizeof(buff)-1, "Trk%03d", route_ctr); -// NEW_STRINGS - remove extr ctor below. - QString name = mkshort(mkshort_handle2, (trk->rte_name != NULL) ? QString(trk->rte_name) : buff); + + QString name = mkshort(mkshort_handle2, trk->rte_name.isEmpty() ? buff : trk->rte_name); /* Carto Exploreur (popular in France) chokes on trackname headers, * so provide option to supppress these. */ diff --git a/gpsbabel/psitrex.cc b/gpsbabel/psitrex.cc index aa56215ff..7055e28fd 100644 --- a/gpsbabel/psitrex.cc +++ b/gpsbabel/psitrex.cc @@ -500,21 +500,12 @@ psit_routehdr_w(gbfile* psit_file, const route_head* rte) } /* route name */ -#if NEW_STRINGS if (rte->rte_name.isEmpty()) { sprintf(hdr, "Route%04x", (unsigned) uniqueValue); rname = xstrdup(hdr); } else { rname = xstrdup(rte->rte_name); } -#else - if (!rte->rte_name) { - sprintf(hdr, "Route%04x", (unsigned) uniqueValue); - rname = xstrdup(hdr); - } else { - rname = xstrdup(rte->rte_name); - } -#endif /* check for psitrex comment sign; replace with '$' */ while ((c = strchr(rname, '#'))) { *c = '$'; @@ -667,11 +658,7 @@ psit_trackhdr_w(gbfile* psit_file, const route_head* trk) } /* track name */ -#if NEW_STRINGS if (trk->rte_name.isEmpty()) { -#else - if (!trk->rte_name) { -#endif sprintf(hdr, "Track%04x", (unsigned) uniqueValue); tname = xstrdup(hdr); } else { diff --git a/gpsbabel/skytraq.cc b/gpsbabel/skytraq.cc index 59030b4e6..081c06b8d 100644 --- a/gpsbabel/skytraq.cc +++ b/gpsbabel/skytraq.cc @@ -664,7 +664,7 @@ make_trackpoint(struct read_state* st, double lat, double lon, double alt) { Waypoint* wpt = new Waypoint; - xasprintf(&wpt->shortname, "TP%04d", ++st->tpn); + wpt->shortname = QString().sprintf("TP%04d", ++st->tpn); wpt->latitude = lat; wpt->longitude = lon; @@ -1529,8 +1529,8 @@ static void miniHomer_get_poi() ECEF_to_LLA(ecef_x, ecef_y, ecef_z, &lat, &lng, &alt); wpt = new Waypoint; - xasprintf(&wpt->shortname, "POI_%s", poinames[poi]); - xasprintf(&wpt->description, "miniHomer points to this coordinates if the %s symbol is on", poinames[poi]); + wpt->shortname = QString().sprintf("POI_%s", poinames[poi]); + wpt->description = QString().sprintf("miniHomer points to this coordinates if the %s symbol is on", poinames[poi]); wpt->latitude = lat; wpt->longitude = lng; wpt->altitude = alt; diff --git a/gpsbabel/stmsdf.cc b/gpsbabel/stmsdf.cc index c1b34a405..3a0e4148d 100644 --- a/gpsbabel/stmsdf.cc +++ b/gpsbabel/stmsdf.cc @@ -216,7 +216,7 @@ finalize_tracks(void) trackno++; if (rte_name != NULL) { if (trackno > 1) { - xasprintf(&track->rte_name, "%s (%d)", CSTR(rte_name), trackno); + track->rte_name = QString("%1 (%2)").arg(rte_name).arg(trackno); } else { track->rte_name = rte_name; } @@ -302,7 +302,7 @@ parse_point(char* line) break; case 3: WAYPT_SET(wpt, proximity, atof(str)); - xasprintf(&wpt->notes, "Alarm point: radius=%s", str); + wpt->notes = QString().sprintf("Alarm point: radius=%s", str); break; } break; @@ -658,8 +658,7 @@ route_disp_wpt_cb(const Waypoint* wpt) if (global_opts.synthesize_shortnames) { sn = mkshort_from_wpt(short_h, wpt); } else { -// NEW_STRINGS: eliminate extra ctor below. - sn = mkshort(short_h, QString(wpt->shortname)); + sn = mkshort(short_h, wpt->shortname); } gbfprintf(fout, "\"WP\",\"%s\",%.8lf,%.8lf,%.f\n", CSTR(sn), wpt->latitude, wpt->longitude, ALT(wpt)); diff --git a/gpsbabel/tiger.cc b/gpsbabel/tiger.cc index f40e2ba07..18a65fae2 100644 --- a/gpsbabel/tiger.cc +++ b/gpsbabel/tiger.cc @@ -213,8 +213,7 @@ tiger_disp(const Waypoint* wpt) gbfprintf(file_out, "%f,%f:%s", lon, lat, pin.toUtf8().data()); if (!nolabels) { QString temp; -// NEW_STRINGS - eliminate extr ctor below. - QString desc = csv_stringclean(QString(wpt->description), ":"); + QString desc = csv_stringclean(wpt->description, ":"); if (global_opts.synthesize_shortnames) { temp = desc; desc = mkshort(mkshort_whandle, desc); diff --git a/gpsbabel/util.cc b/gpsbabel/util.cc index ece38cc04..d28d36e11 100644 --- a/gpsbabel/util.cc +++ b/gpsbabel/util.cc @@ -277,7 +277,7 @@ xasprintf(char** strp, const char* fmt, ...) return res; } -#if NEW_STRINGS + int xasprintf(QString* strp, const char* fmt, ...) { @@ -292,7 +292,6 @@ xasprintf(QString* strp, const char* fmt, ...) return res; } -#endif int xvasprintf(char** strp, const char* fmt, va_list ap) -- 2.30.2